﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script language="javascript">
// location.replace("adminhome.php")

</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>::.::.:: APPMA ::.::.::</title>
<style type="text/css">
<!--
#form1 table tr td label #checkbox {
	text-align: right;
}
-->
</style>
</head>

<body>
<?php
  $message = $_POST["message"];
  $message .="<br>";
	
	
if(($_FILES["file"]["size"])>0)
{ 
$name=$_FILES["file"]["name"];
$img="uploader/files/";
$img.=$_FILES["file"]["name"];
$img2=$_FILES["file"]["size"];

if(($_FILES["file"]["size"])>0)
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("uploader/files/" . $_FILES["file"]["name"]))
      {
/*     echo $_FILES["file"]["name"] . " already exists. ";
*/      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "uploader/files/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "uploader/files/" . $_FILES["file"]["name"];
      }
    }
 }
else
  {
  echo "Invalid file";
  }
    $message .="<a href=http://www.appma.com.pk/uploader/files/" . $name . " target='_blank'>Download Newsletter</a><br>";

$con = mysql_connect("localhost","appma" ,"database");
	mysql_select_db("162_appma", $con);
$sql="INSERT INTO  files VALUES ('$name', 'admin')";
if (!mysql_query($sql,$con))
{
echo "<br>An Error Occured to update database";

}  


echo "<br>file uploaded successfully";
}


  
 $subject="News Letter";
$con = mysql_connect("localhost","appma" ,"database");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
	mysql_select_db("162_appma", $con);
	  $sql="SELECT * FROM newsletter";
  if (!$sql)
		  {
		  die('Could Not Complete Please Try Again Later: ' );
		  }
$to  = 'mobashir_s@yahoo.com, '; 
 		 $result=mysql_query($sql);
		while($row = mysql_fetch_array($result))
		  {
		  $to  .= $row['Email'];
		  $to  .= ", ";
		  }
  		$DBresult = mysql_query($result, $con);



$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$headers .= 'To: Kelly <mobashir_s@yahoo.com>' . "\r\n";
$headers .= 'From: Mobashir <mobashir_s@yahoo.com>' . "\r\n";
$headers .= 'Cc: email@yaho.com' . "\r\n";
$headers .= 'Bcc: email@yaho.com' . "\r\n";

// Mail it

$a= mail($to, $subject, $message, $headers);

if(!$a)
{
echo "<br>An Error Occured to send Email";
}

else
{

echo '<br><font  style="color:#FFF">Thank You!!</font>';
}
?>



</body>
</html>
